<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/text.css">

    <script src="./utils/flexible.js"></script>
</head>

<body>
    <header id="header">
        <div class="left">
            <a href="#"><img src="http://chst.vip:8081/for-stu/wfzh/images/header_logo.png" width="70" alt=""></a>
        </div>
        <div class="right"><a href="#"><img src="./images/header_app.png" alt="" width="34"></a>
        </div>
    </header>
    <section id="search">
        <div class="searchbox">
            <input type="text" name placeholder="请输入你想比价的产品">
        </div>
        <div class="button">
        </div>
    </section>
    <!-- 菜单 -->
    <div class="nav">
        <!-- <ul class="">
            
        </ul> -->
    </div>

    <h3>超值折扣推荐</h3>
    <section class="discount">
    
</section>
    <h3>品牌排行</h3>
    <ul class="last">
        <li>
            <a href="#">登入</a>
        </li>
        <li>
            <a href="#" class="resign">注册</a>
        </li>
        <li>
            <a href="#" class="return">返回顶部</a>
        </li>
        </div>
    </ul>
</body>
  
</html>
<script src="./utils/utils.js"></script>
<script>

let uu = document.querySelector('.nav')
    let el = "";
    fetch('http://chst.vip:1234/api/getindexmenu')
        .then(body => body.json())
        .then(res => {
            console.log(res)

            res.result.forEach(item => {
                let regExp = /^<[^<]+\s+src="([^''""]*)"/;
                let result = item.img.match(regExp)
                el += `<ul>
                    <li>
                        <a href="./pages/${item.titlehref}">
                        <img widht="50" src=${result[1]}>
                        <b>${item.name}</b>
                        </a>
                        </li></ul>`
            })
            uu.innerHTML = el;
        })
        
     let uu1=document.querySelector('.discount')
        let el1= "";
    fetch('http://chst.vip:1234/api/getmoneyctrl')
        .then(body => body.json())
        .then(res => {
            console.log(res)
            res.result.forEach(item => {
                let regExp = /(?<=imgurl=)[^'"]*/;

                let r = item.productImg2.match(regExp);
                console.log(1)
                console.log(r)
                el1 += `<li productid=${item.productId}>
                    <img src=${r[0]} height="100" alt="">
                    <b>${item.productName}</b>
                </li>`
            })
            uu1.innerHTML = el1;
        })

        uu1.onclick = function (e) {
        if (e.target.localName === 'li') {
            let _this = e.target;
            console.log(_this)

            //获取当前li标签的productid

            let id = _this.getAttribute('productid')

            console.log(id)

            location.href = './indexXiang.html?productid=' + id
        }
    }
</script>